package com.yourcompany.web.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.yourcompany.api.service.PermissionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "权限管理")
@RestController
@RequestMapping("/api/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @Operation(summary = "获取权限树")
    @GetMapping("/tree")
    public SaResult getPermissionTree() {
        return SaResult.ok().setData(permissionService.getPermissionTree());
    }

    @Operation(summary = "获取当前用户权限树")
    @GetMapping("/user/tree")
    public SaResult getUserPermissionTree() {
        return SaResult.ok().setData(permissionService.getUserPermissionTree(StpUtil.getLoginIdAsLong()));
    }

    @Operation(summary = "获取当前用户菜单树")
    @GetMapping("/user/menu")
    public SaResult getUserMenuTree() {
        return SaResult.ok().setData(permissionService.getUserMenuTree(StpUtil.getLoginIdAsLong()));
    }
} 